package com.jinlia.show.modules.base.system.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jinlia.show.modules.base.system.entity.MdArticle;
import com.jinlia.show.modules.base.system.mapper.MdArticleMapper;
import org.springframework.stereotype.Service;

@Service
public class MdArticleMapperService extends ServiceImpl<MdArticleMapper, MdArticle> {
    /**
     * 重命名文章
     *
     * @param mdArticle
     */
    public void renameArticle(MdArticle mdArticle) {
        MdArticle one = this.lambdaQuery()
                .eq(MdArticle::getTitle, mdArticle.getTitle())
                .one();
        if (one != null && one.getId() != mdArticle.getId()) {
            throw new RuntimeException("文章标题已存在");
        }
        this.lambdaUpdate()
                .eq(MdArticle::getId, mdArticle.getId())
                .set(MdArticle::getTitle, mdArticle.getTitle())
                .update();

    }
}
